package com.xmut.mall.member.controller;

import com.xmut.mall.member.annotation.CheckJwt;
import com.xmut.mall.member.service.MemberCouponRelationService;
import com.xmut.mall.member.utils.RespBean;
import com.xmut.mall.member.vo.MemberCouponVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("member/membercouponrelation")
public class MemberCouponRelationController {

    @Autowired
    private MemberCouponRelationService memberCouponRelationService;



    /**
     * 用户领取优惠券
     * @param params
     * @return
     */
    @CheckJwt
    @PostMapping("/userReceiveCoupon")
    public RespBean userReceiveCoupon(@RequestBody Map<String,Object> params){
        return memberCouponRelationService.userReceiveCoupon(params);
    }


    /**
     * 查询用户领取了几次当前id的优惠券
     * @param couponId
     * @param userId
     * @return
     */
    @CheckJwt
    @GetMapping("/getUserReceiveCouponNum/{couponId}/{userId}")
    public RespBean getUserReceiveCouponNum(@PathVariable("couponId") Long couponId,@PathVariable("userId") Long userId){
        return memberCouponRelationService.getUserReceiveCouponNum(couponId,userId);
    }

    /**
     * 获取用户的优惠券(分页)
     * @param params
     * @return
     */
    @CheckJwt
    @PostMapping("/getUserCouponByPage")
    public RespBean getUserCouponByPage(@RequestBody Map<String,Object> params){
        MemberCouponVo vo = memberCouponRelationService.getUserCouponByPage(params);
        return RespBean.success("获取成功",vo);
    }


    /**
     * 用户领取优惠券
     * @param memberId
     * @param couponId
     * @return
     */
    @CheckJwt
    @GetMapping("/receive/{memberId}/{couponId}")
    public RespBean receiveCoupon(@PathVariable("memberId") Long memberId,@PathVariable("couponId") Long couponId){
        return memberCouponRelationService.receiveCoupon(memberId,couponId);
    }
}
